package com.slx.contains_duplicate;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    /**
     * Given an array of integers, find if the array contains any duplicates.
     * Your function should return true if any value appears at least twice in the
     * array, and it should return false if every element is distinct.
     * <p>
     * @param nums
     * @return
     */
    public boolean containsDuplicate(int[] nums) {

        if (nums != null && nums.length > 1) {
            Set<Integer> set = new HashSet<>(nums.length);
            for (int i : nums) {
                if (set.contains(i)) {
                    return true;
                }
                else {
                    set.add(i);
                }
            }
        }

        return false;
    }
}
